﻿package Cain.mk
{
	import Cain.arr_acc;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import caurina.transitions.Tweener;
	import flash.geom.Rectangle;
	public class fly_in 
	{
		private var mc:DisplayObject;
		private var _mk_width:Number = 50;
		private var _x_n:int;
		private var _y_n:int;
		private var _mk_arr:Array;
		private var p_x:Number;
		private var p_y:Number;
		public function fly_in(_mc:DisplayObject) 
		{
			mc = _mc;
			init();
		}
		
		private function init():void
		{
			num_init();
			mk_init();
			
			for (var i:int = 0; i < _y_n; i++) 
			{
				for (var j:int = 0; j < _x_n; j++) 
				{
					_mk_arr[i][j].scaleX = 0;
					_mk_arr[i][j].scaleY = 0;
					_mk_arr[i][j].y -= 100 ;
					_mk_arr[i][j].rotation = 60;
					Tweener.addTween(_mk_arr[i][j],{ scaleX:1, scaleY:1, y:_mk_arr[i][j].y+100,rotation:0, time: 1, delay:j *.05+i*.05,transition:"easeOutCirc"});
				}
			}
			
		}
		private function num_init():void 
		{
			var rc:Rectangle = mc.getRect(mc);
			p_x = rc.x;
			p_y = rc.y;
			_x_n = Math.floor(mc.width / _mk_width);
			if (mc.width % _mk_width != 0)
			{
				_x_n++;
			}
			_y_n = Math.floor(mc.height / _mk_width);
			if (mc.width % _mk_width != 0)
			{
				_y_n++;
			}
		}
		private function mk_init():void 
		{
			_mk_arr = new Array();
			var _mk_mv:Sprite = new Sprite();
			_mk_mv.cacheAsBitmap = true;
			Sprite(mc).addChild(_mk_mv);
			mc.mask = _mk_mv;
			for (var i:int = 0; i < _y_n; i++) 
			{
				var _arr_x = new Array();
				for (var j:int = 0; j < _x_n; j++) 
				{
					var _mk:Mk = new Mk();
					_mk.x = (j * _mk_width + _mk_width / 2)+p_x;
					_mk.y = (i * _mk_width + _mk_width / 2)+p_y;
					_mk_mv.addChild(_mk);
					_arr_x.push(_mk);
				}
				_mk_arr.push(_arr_x);
			}
		}
	}
	
}